package model;


/**
 * The QuantifiedComponent class contains a Component and an Integer representing the quantity of the Component.
 * @author hfi411pi
 *
 */
public class QuantifiedComponent {
	
	/**
	 * Factory method for creating QuantifiedComponents.
	 * @param quantity is the quantity of the Component.
	 * @param component is the Component to use.
	 * @return the created QuantifiedComponent.
	 */
	public static QuantifiedComponent createQuantifiedComponent (final int quantity, final ComponentCommon component){
		return new QuantifiedComponent(quantity,component);
	}
	private int quantity;
	final private ComponentCommon component;
	
	/**
	 * Constructor of QuantifiedComponent.
	 * @param quantity is the quantity of the Component.
	 * @param component is the Component to use.
	 */
	private QuantifiedComponent(final int quantity, final ComponentCommon component){
		this.quantity = quantity;
		this.component = component;
	}

	public ComponentCommon getComponent() {
		return component;
	}

	public String getName(){
		return this.component.getName();
	}
	
	public int getQuantity() {
		return quantity;
	}
	public void setQuantity(final int quantity){
		this.quantity = quantity;
	}

	/** Provides whether a component is part of this component.
	 * @param part is the component to search for in the parts of this component.
	 * @return true if part is a component of this. Else returns false.
	 */
	public boolean contains(final ComponentCommon part) {
		return this.getComponent().contains(part);
	}
	
	/** Provides the number of materials this component consists of.
	 * @return the number of materials.
	 */
	public int getNumberOfMaterials() {
		return this.getComponent().getNumberOfMaterials() * this.getQuantity();
	}

	@Override
	public String toString() {
		return this.getComponent().toString() + "(" + this.getQuantity() + ")";
	}

}
